package gold.digger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC629 {
    public long startExecuteTime = System.currentTimeMillis();

    /*
     * @param 此题目参考了别人代码
     * 这是因为问题情况较为复杂
     * 未来需要再次复习此道题目
     * Hard 难度，别人的玩具～～
     * @return:
     */
    class Solution {
        int mod = (int) 1e9 + 7;

        public int kInversePairs(int n, int k) {
            int[][] f = new int[n + 1][k + 1];
            int[][] sum = new int[n + 1][k + 1];
            f[1][0] = 1;
            Arrays.fill(sum[1], 1);
            for (int i = 2; i <= n; i++) {
                for (int j = 0; j <= k; j++) {
                    f[i][j] = j < i ? sum[i - 1][j] : (sum[i - 1][j] - sum[i - 1][j - (i - 1) - 1] + mod) % mod;
                    sum[i][j] = j == 0 ? f[i][j] : (sum[i][j - 1] + f[i][j]) % mod;
                }
            }
            return f[n][k];
        }
    }


    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC629 an = new LC629();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
